package com.ysd.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ysd.entity.OrderForm;
import com.ysd.entity.Product;
import com.ysd.entity.User;
import com.ysd.service.OrderFormService;
import com.ysd.util.Result;

@Controller
public class OrderFormController {
	
	@Autowired
	private OrderFormService orderFormService;
	
	@RequestMapping("getOrderForms")
	@ResponseBody
	public Object getOrderForms(int uid) {
		List<OrderForm> list = orderFormService.findOrderForm(uid);
		return list;
	}
	
	@RequestMapping("delectOrderForms")
	@ResponseBody
	public Object delectOrderForms(OrderForm orderForm) {
		int n = orderFormService.delectOrderForm(orderForm);
		return n;
	}
	
	@RequestMapping("getTiJiao")
	@ResponseBody
	public Object getTiJiao(OrderForm orderForm) {
		int n = orderFormService.getTiJiao(orderForm);
		if(n>0) {
			return Result.toClient("0", "��ӳɹ�");
		}else {
			return Result.toClient("1", "���ʧ��");
		}
	}
	
	@RequestMapping("getOrder")
	@ResponseBody
	public Object getOrder(OrderForm of,Product product,User user) {
		
		of.setPage((of.getPage()-1)*of.getLimit());
		
		System.err.println(product);
		List<OrderForm> list = orderFormService.getOrder(of,product,user);
		int count = orderFormService.getCount(of,product,user);
		if(list!=null) {
			System.out.println(list);
			return Result.toClient("0", "��ѯ�ɹ�", count, list);
		}else {
			return Result.toClient("1", "��ѯʧ��", 0, list);
		}
	}
	
	
	@RequestMapping("shiFouFaHuo")
	@ResponseBody
	public Object shiFouFaHuo() {
		List<OrderForm> list = orderFormService.shiFouFaHuo();
		return list;
	}
	@RequestMapping("shiFouShouHuo")
	@ResponseBody
	public Object shiFouShouHuo() {
		List<OrderForm> list = orderFormService.shiFouShouHuo();
		return list;
	}
	

	
	@RequestMapping("updateFaHuo")
	@ResponseBody
	public Object updateFaHuo(OrderForm orderform) {
		int n = orderFormService.updateFaHuo(orderform);
		if(n>0) {
			return Result.toClient("0", "发货成功");
		}else {
			return Result.toClient("1", "发货失败");
		}
	}
	
	
	
	@RequestMapping("faHuo")
	@ResponseBody
	public Object faHuo(int uid) {
		List<OrderForm> list = orderFormService.faHuo(uid);
		return list;
	}

	
	@RequestMapping("faHuo1")
	@ResponseBody
	public Object faHuo1(int uid) {
		List<OrderForm> list = orderFormService.faHuo1(uid);
		return list;
	}

	
	@RequestMapping("shouHuo")
	@ResponseBody
	public Object shouHuo(int uid) {
		List<OrderForm> list = orderFormService.shouHuo(uid);
		return list;
	}

	
	@RequestMapping("shouHuo1")
	@ResponseBody
	public Object shouHuo1(int uid) {
		List<OrderForm> list = orderFormService.shouHuo1(uid);
		return list;
	}
	
	@RequestMapping("updateOrderForm")
	@ResponseBody
	public Object updateOrderForm(OrderForm of) {
		int n = orderFormService.updateOrderForm(of);
		if (n>0) {
			return Result.toClient("0", "已收货", null, n);
		} else {
			return Result.toClient("1", "收货失败", null, null);
		}
	}
	
	
	
}
